package com.boc.langxiang.presenter.index;


import com.boc.langxiang.contract.index.HotArticleContract;
import com.boc.langxiang.entity.request.HotArticleRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.IndexArticleContent;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CreateTime: 2016-06-14上午10:40
 * Author: wjkjinke00@126.com
 * Description:
 */
public class HotArticlePresenter implements HotArticleContract.Presenter {

    private final ApiService mService;
    private HotArticleContract.View mView;

    public HotArticlePresenter(HotArticleContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        mView = view;
    }


    @Override
    public void getSpcialList(HotArticleRequest request) {
        mView.showLoading();
        mService.getList(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<IndexArticleContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<IndexArticleContent> response) {
                        mView.getFlagSuccess(response.getContent().getGetList());
                    }
                });
    }
}
